package cn.kmsoft.stgeometry.util;


import cn.kmsoft.common.utils.StringUtil;
import cn.kmsoft.stgeometry.landm.StgeoFeature;
import cn.kmsoft.stgeometry.landm.StgeoFeature2;
import cn.kmsoft.wololo.jts2geojson.GeoJSONReader;
import cn.kmsoft.wololo.object.GeoJson;
import cn.kmsoft.wololo.object.GeoJsonFeature;
import cn.kmsoft.wololo.object.GeoJsonGeometry;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vividsolutions.jts.geom.*;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.io.WKTWriter;
import org.geotools.data.DataUtilities;
import org.geotools.data.collection.ListFeatureCollection;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.SchemaException;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.geojson.feature.FeatureJSON;
import org.geotools.geojson.geom.GeometryJSON;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.opengis.feature.GeometryAttribute;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.*;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystem;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.*;


/**
 * JTS框架类库下WKT数据操作类,主要是完成WKT的面和多面的图形构建以及与GeoJson格式的转换操作；
 *
 * @author cqwensten 2020-08-05
 *  email:cqwensten@163.com
 *
 */
public class JTSGeometryWKTUtil {
    private static GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);

    public static String getGeoTypeFromWkt(String wkt) {
        String geoType = null;

        WKTReader reader = new WKTReader(geometryFactory);
        try {
            Geometry geometry= reader.read(wkt);
            geoType = geometry.getGeometryType();
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return geoType;
    }

    /**
     * getShpType：获取shp的图形类型名称
     * tips: 类型名称包括Point MultiPoint Polygon MutiPolygon LineString  MultiLineString
     *
     * @param shpPath
     * @return
     */
    public static String getShpType(String shpPath) {
        String geoType="";
        try {
            ShapefileDataStore shapefileDataStore = new ShapefileDataStore(new File(shpPath).toURI().toURL());
            FeatureCollection featureCollection = shapefileDataStore.getFeatureSource().getFeatures();
            SimpleFeatureIterator feaIter = (SimpleFeatureIterator) featureCollection.features();
            while (feaIter.hasNext()) {
                SimpleFeature next = feaIter.next();

                Geometry geometry = (Geometry) next.getDefaultGeometry();
                // Point MultiPoint Polygon MutiPolygon LineString  MultiLineString
                geoType = geometry.getGeometryType();
                if( !StringUtil.isNullOrEmpty(geoType)) {
                    break;
                }
            }
            feaIter.close();
            shapefileDataStore.dispose();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally{
            //
        }
        return geoType;
    }

    /**
     * getShpCrsName 获取Shp投影坐标名称
     *
     * @param shpPath
     * @return
     */
    public static String getShpCrsName(String shpPath) {
        String crsName="";

        ShapefileDataStore shapefileDataStore=null;
        try {
            shapefileDataStore = new ShapefileDataStore(new File(shpPath).toURI().toURL());
            FeatureCollection featureCollection = shapefileDataStore.getFeatureSource().getFeatures();
            SimpleFeatureIterator feaIter = (SimpleFeatureIterator) featureCollection.features();
            while (feaIter.hasNext()) {
                SimpleFeature feature = feaIter.next();

                GeometryAttribute geometryAttribute = feature.getDefaultGeometryProperty();
                // 获取坐标参考系信息
                CoordinateReferenceSystem coordinateReferenceSystem = geometryAttribute.getDescriptor().getCoordinateReferenceSystem();
                // geometry类型
                GeometryType geometryType = geometryAttribute.getType();
                // geometry类型名称
                Name name = geometryType.getName();
                CoordinateSystem crs = coordinateReferenceSystem.getCoordinateSystem();
                crsName= crs.getName().getCode();
                if(!StringUtil.isNullOrEmpty(crsName)) {
                    break;
                }
            }
            feaIter.close();
            shapefileDataStore.dispose();
        } catch (Exception ex) {
            if( shapefileDataStore!=null ){
                shapefileDataStore.dispose();
            }
            ex.printStackTrace();
        }finally{
            //
        }

        return crsName;
    }


    public static String jtsGeom2wkt(Geometry geom) {
        String wkt=null;
        try {
            WKTWriter write = new WKTWriter();
            wkt=write.write(geom);
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
        return wkt;

    }

    /**
     * 获取GeomStr的图形类型
     *
     * @param geomStr
     * @return
     */
    public static String getGeomType(String geomStr){
        JSONObject geoObject = JSON.parseObject(geomStr);
        String geoType = geoObject.getString("type");
        return geoType;
    }

    /**
     * 将GeomStr图形坐标串转换为WKT
     *
     * @param geomStr
     * @return
     */
    public static String geomStr2wkt(String geomStr){
        String wkt = "";

        JSONObject geoObject = JSON.parseObject(geomStr);
        String geoType = geoObject.getString("type");
        switch(geoType.toLowerCase()) {
            case "polygon":
            {
                StringBuilder sb = new StringBuilder();
                sb.append("POLYGON(");
                //double[][][]  polygonCoords
                JSONArray polygonCoord = geoObject.getJSONArray("coordinates");
                for (int i = 0; i < polygonCoord.size(); i++) {
                    sb.append("(");
                    JSONArray lineCoord = polygonCoord.getJSONArray(i);
                    for (int j = 0; j < lineCoord.size(); j++) {
                        // point
                        JSONArray ptCoords = lineCoord.getJSONArray(j);
                        double x = ptCoords.getDoubleValue(0);
                        double y = ptCoords.getDoubleValue(1);

                        String coordLine=String.format("%f %f", x, y);
                        if(!StringUtil.isNullOrEmpty(coordLine)) {
                            sb.append(coordLine);
                        }
                        sb.append(",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append("),");
                }
                sb.deleteCharAt(sb.length() - 1);
                sb.append(")");

                wkt=sb.toString();

                break;
            }
            case "multipolygon": {
                StringBuilder sb = new StringBuilder();
                sb.append("MULTIPOLYGON(");

                JSONArray multiPolygonCoords = geoObject.getJSONArray("coordinates");
                for (int i = 0; i < multiPolygonCoords.size(); i++) {
                    sb.append("(");
                    JSONArray polygonCoords = multiPolygonCoords.getJSONArray(i);
                    for (int j = 0; j < polygonCoords.size(); j++) {
                        sb.append("(");
                        // ring
                        JSONArray ringCoords = polygonCoords.getJSONArray(j);
                        for (int k = 0; k < ringCoords.size(); k++) {
                            // point
                            JSONArray ptCoords = ringCoords.getJSONArray(k);
                            double x = ptCoords.getDoubleValue(0);
                            double y = ptCoords.getDoubleValue(1);

                            String coordLine = String.format("%f %f", x, y);
                            if (!StringUtil.isNullOrEmpty(coordLine)) {
                                sb.append(coordLine);
                            }
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append("),");
                }
                sb.deleteCharAt(sb.length() - 1);
                sb.append(")");

                wkt = sb.toString();
                break;
            }
        }

        return wkt;
    }

//    public static String locGeom2wkt(org.locationtech.jts.geom.Geometry geom) {
//        String wkt=null;
//        try {
//            org.locationtech.jts.io.WKTWriter write = new org.locationtech.jts.io.WKTWriter();
//            wkt=write.write(geom);
//        }
//        catch(Exception ex) {
//            ex.printStackTrace();
//        }
//        return wkt;
//
//    }


    /**
     * json2Wkt geojson转换为wkt
     *
     * @param gjsonStr 这里要求是com.vividsolutions.jts.geom.Geometry的geojson字符串
     *
     * @return
     */
    public static String json2Wkt(String gjsonStr) {
        String wkt = null;
        GeometryJSON gjson = new GeometryJSON();
        Reader reader = new StringReader(gjsonStr);
        try {
            // 要求传入的是com.vividsolutions.jts.geom.Geometry
            Geometry geometry = gjson.read(reader);
            wkt = geometry.toText();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return wkt;
    }

    public static String json2WktEx(String gjsonStr) {
        String wkt = null;
        GeometryJSON gjson = new GeometryJSON();
        Reader reader = new StringReader(gjsonStr);
        GeoJSONReader geoReader = new GeoJSONReader();
        try {
            Geometry geometry= geoReader.read(gjsonStr);
            // 要求传入的是com.vividsolutions.jts.geom.Geometry
            //Geometry geometry = gjson.read(reader);
            wkt = geometry.toText();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return wkt;
    }

    public static String geo2Json(String wkt,Map<String,Object> map) {
        String json = null;
        try {
            WKTReader reader = new WKTReader(geometryFactory);
            Geometry geometry = reader.read(wkt);
            StringWriter writer = new StringWriter();
            GeometryJSON g = new GeometryJSON();
            g.write(geometry, writer);

            map.put("geometry", writer);

            json = JSONObject.toJSONString(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }


    /**
     * create a point
     *
     * @return
     */
    public static Point createPoint(double x, double y) {
        // Coordinate coord = new Coordinate(109.013388, 32.715519);
        Coordinate coord = new Coordinate(x, y);
        Point point = geometryFactory.createPoint(coord);
        return point;
    }

    /**
     * create a rectangle(矩形)
     *
     * @param x1 the first x-value
     * @param x2 the second x-value
     * @param y1 the first y-value
     * @param y2 the second y-value
     * @return
     */
    public static Envelope createEnvelope(double x1, double x2, double y1, double y2) {
        // Envelope envelope = new Envelope(0,1,0,2);
        Envelope envelope = new Envelope(x1, x2, y1, y2);
        return envelope;
    }

    /**
     * create a point by WKT
     *
     * @return
     * @throws ParseException
     */
    public static Point createPointByWKT(String wkt) throws ParseException {
        WKTReader reader = new WKTReader(geometryFactory);
        // Point point = (Point) reader.read("POINT (109.013388 32.715519)");
        Point point =null;
        try {
            point = (Point) reader.read(wkt);
        }catch(ParseException e) {
            e.printStackTrace();
        }
        return point;
    }

    /**
     * create multiPoint by wkt
     *
     * @return
     */
    public static MultiPoint createMulPointByWKT(String wkt) throws ParseException {
        WKTReader reader = new WKTReader(geometryFactory);
        // MultiPoint mpoint = (MultiPoint) reader.read("MULTIPOINT(109.013388
        // 32.715519,119.32488 31.435678)");
        MultiPoint mpoint = (MultiPoint) reader.read(wkt);
        return mpoint;
    }

    /**
     *
     * create a line
     *
     * @return
     */
    public static LineString createLine() {
        Coordinate[] coords = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
        LineString line = geometryFactory.createLineString(coords);
        return line;
    }

    /**
     * create a line by WKT
     *
     * @return
     * @throws ParseException
     */
    public static LineString createLineByWKT() throws ParseException {
        WKTReader reader = new WKTReader(geometryFactory);
        LineString line = (LineString) reader.read("LINESTRING(0 0, 2 0)");
        return line;
    }
    public static LineString createLineByWKT(String wkt) throws ParseException {
        WKTReader reader = new WKTReader(geometryFactory);
        //LineString line = (LineString) reader.read("LINESTRING(0 0, 2 0)");
        LineString line=null;
        try {
            line = (LineString) reader.read(wkt);
        }catch(ParseException e) {
            e.printStackTrace();
        }
        return line;
    }

    /**
     * create multiLine
     *
     * @return
     */
    public static MultiLineString createMLine() {
        Coordinate[] coords1 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
        LineString line1 = geometryFactory.createLineString(coords1);
        Coordinate[] coords2 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
        LineString line2 = geometryFactory.createLineString(coords2);
        LineString[] lineStrings = new LineString[2];
        lineStrings[0] = line1;
        lineStrings[1] = line2;
        MultiLineString ms = geometryFactory.createMultiLineString(lineStrings);
        return ms;
    }

    /**
     * create multiLine by WKT
     *
     * @return
     * @throws ParseException
     */
    public static MultiLineString createMLineByWKT() throws ParseException {
        WKTReader reader = new WKTReader(geometryFactory);
        MultiLineString line = (MultiLineString) reader.read("MULTILINESTRING((0 0, 2 0),(1 1,2 2))");
        return line;
    }

    /**
     * create a polygon(多边形) by WKT
     *
     * @return
     * @throws ParseException
     */
    public static Polygon createPolygonByWKT(String wkt) {
        WKTReader reader = new WKTReader(geometryFactory);
        // Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20,
        // 20 10))");
        Polygon polygon=null;
        try {
            polygon = (Polygon) reader.read(wkt);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return polygon;
    }

    /**
     * create multi polygon by wkt
     *
     * @return
     * @throws ParseException
     */
    public static MultiPolygon createMulPolygonByWKT(String wkt) {
        WKTReader reader = new WKTReader(geometryFactory);
        // MultiPolygon mpolygon = (MultiPolygon) reader.read("MULTIPOLYGON(((40 10, 30
        // 0, 40 10, 30 20, 40 10),(30 10, 30 0, 40 10, 30 20, 30 10)))");
        MultiPolygon mpolygon=null;
        try {
            mpolygon= (MultiPolygon) reader.read(wkt);
        }
        catch(ParseException ex) {
            ex.printStackTrace();
        }
        return mpolygon;
    }

    /**
     * create GeometryCollection contain point or multiPoint or line or multiLine or
     * polygon or multiPolygon
     *
     * @return
     * @throws ParseException
     */
    public static GeometryCollection createGeoCollect() throws ParseException {
        LineString line = createLine();

        String wkt = "POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))";
        Polygon poly = createPolygonByWKT(wkt);
        Geometry g1 = geometryFactory.createGeometry(line);
        Geometry g2 = geometryFactory.createGeometry(poly);
        Geometry[] garray = new Geometry[] { g1, g2 };
        GeometryCollection gc = geometryFactory.createGeometryCollection(garray);
        return gc;
    }

    /**
     * create a Circle 创建一个圆，圆心(x,y) 半径RADIUS
     *
     * @param x
     * @param y
     * @param RADIUS
     * @return
     */
    public static Polygon createCircle(double x, double y, final double RADIUS) {
        final int SIDES = 32;// 圆上面的点个数
        Coordinate coords[] = new Coordinate[SIDES + 1];
        for (int i = 0; i < SIDES; i++) {
            double angle = ((double) i / (double) SIDES) * Math.PI * 2.0;
            double dx = Math.cos(angle) * RADIUS;
            double dy = Math.sin(angle) * RADIUS;
            coords[i] = new Coordinate((double) x + dx, (double) y + dy);
        }
        coords[SIDES] = coords[0];
        LinearRing ring = geometryFactory.createLinearRing(coords);
        Polygon polygon = geometryFactory.createPolygon(ring, null);
        return polygon;
    }


    //wkt
    /**
     * getMultiPolygonText- 获取图形的界址点坐标序列
     *
     * @param multiPolygon  com.vividsolutions.jts.geom.MultiPolygon类型多面图形
     * @return
     * @throws ParseException
     */
    private static String getMultiPolygonText(MultiPolygon multiPolygon) throws ParseException {
        Polygon polygon;
        int num = multiPolygon.getNumGeometries();
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i < num; i++) {
            polygon = (Polygon) multiPolygon.getGeometryN(i);
            sb.append(getPolygonText(polygon) + ",");
        }
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }

    private static String getPolygonText(Polygon polygon) {
        String result;

        int num = polygon.getNumInteriorRing();
        if (num > 0) {
            StringBuffer sb = new StringBuffer("[" + getLineStringText(polygon.getExteriorRing()) + ",");
            for (int i = 0; i < num; i++) {
                sb.append(getLineStringText(polygon.getInteriorRingN(i)) + ",");
            }
            sb.setCharAt(sb.length() - 1, ']');
            result = sb.toString();
        } else {
            result = "[" + getLineStringText(polygon.getExteriorRing()) + "]";
        }
        return result;
    }

    private static String getLineStringText(LineString lineString) {
        Coordinate[] corrds = lineString.getCoordinates();
        StringBuffer sb = new StringBuffer("[");
        for (Coordinate corrd : corrds) {
            sb.append(getCoordinateText(corrd) + ",");
        }
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }

    private static String getMultiLineStringText(MultiLineString multiLineString) {
        LineString lineString;
        int num = multiLineString.getNumGeometries();
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i < num; i++) {
            lineString = (LineString) multiLineString.getGeometryN(i);
            sb.append(getLineStringText(lineString) + ",");
        }
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }

    private static String getMultiPointText(MultiPoint multiPoint) {
        Point point;
        int num = multiPoint.getNumGeometries();
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i < num; i++) {
            point = (Point) multiPoint.getGeometryN(i);
            sb.append(getPointText(point) + ",");
        }
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }
    private static String getPointText(Point point) {
        return getCoordinateText(point.getCoordinate());
    }

    private static String getCoordinateText(Coordinate coord) {
        return "[" + coord.x + "," + coord.y + "]";
    }

    public static String getGeoTextFromWkt(Geometry geom) throws ParseException {
        // wkt描述的图形分为POINT、MULTIPOINT、LINESTRING、MULTILINESTRING、POLYGON、MULTIPOLYGON这几种类型。
        String result = null;

        // Geometry geom = wktReader.read(wkt);
        String geomType = geom.getClass().getSimpleName().toLowerCase();
        if (geomType.equals("point")) {
            Point point = (Point) geom;
            result = getPointText(point);
        } else if (geomType.equals("linestring")) {
            LineString lineString = (LineString) geom;
            result = getLineStringText(lineString);
        } else if (geomType.equals("polygon")) {
            Polygon polygon = (Polygon) geom;
            result = getPolygonText(polygon);
        } else if (geomType.equals("multipoint")) {
            MultiPoint multiPoint = (MultiPoint) geom;
            result = getMultiPointText(multiPoint);
        } else if (geomType.equals("multilinestring")) {
            MultiLineString multiLineString = (MultiLineString) geom;
            result = getMultiLineStringText(multiLineString);
        } else if (geomType.equals("multipolygon")) {
            MultiPolygon multiPolygon = (MultiPolygon) geom;
            result = getMultiPolygonText(multiPolygon);
        }

        return result;
    }

    /**
     * wkt2json wkt转换为json
     *
     * @param wkt
     * @param map 相关的属性：字段和字段值
     * @return
     */
    public static String wkt2Json(String wkt, Map<String, Object> map) {
        String jsonStr = null;

        try {
            StringWriter writer = new StringWriter();

            WKTReader reader = new WKTReader(geometryFactory);
            Geometry geo = reader.read(wkt);
            // org.geotools.geojson.geom.GeometryJSON
            GeometryJSON geoJson = new GeometryJSON();
            geoJson.write(geo, writer);
            map.put("geometry", writer);

            // jsonStr = com.alibaba.fastjson.JSONObject.toJSONString(map);
            jsonStr = org.json.simple.JSONObject.toJSONString(map);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonStr;
    }

    /**
     * wkt2json wkt转换为GeoJson
     *
     * @param wkts
     * @param geoType 相关的属性：字段和字段值
     * @return
     */
    public static String wkt2GeoJson(List<String> wkts,String geoType) throws SchemaException, ParseException, IOException {
        String jsonStr = null;

        if(wkts==null || wkts.size()==0){
            return jsonStr;
        }

        SimpleFeatureType TYPE=null;
        if("polygon".equalsIgnoreCase(geoType)) {
            TYPE = DataUtilities.createType("Link", "geometry:Polygon");
        }else if("multipolygon".equalsIgnoreCase(geoType)) {
            TYPE = DataUtilities.createType("Link", "geometry:MultiPolygon");
        }else{
            System.out.println(String.format("--->wkt2GeoJson TYPE=null, geoType: %s ",geoType));
        }
        if(TYPE !=null) {
            SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);

            //GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
            WKTReader reader = new WKTReader(geometryFactory);
            FeatureJSON fjson = new FeatureJSON();

            List<SimpleFeature> features = new ArrayList<>();
            SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);
            for (String wkt : wkts) {
                System.out.println("--->wkt2GeoJson : " + wkt);
                //转换wkt为polygon
                if ("polygon".equalsIgnoreCase(geoType)) {
                    Polygon polygon = (Polygon) reader.read(wkt);
                    featureBuilder.add(polygon);
                } else if ("multipolygon".equalsIgnoreCase(geoType)) {
                    MultiPolygon multipolygon = (MultiPolygon) reader.read(wkt);
                    featureBuilder.add(multipolygon);
                }

                SimpleFeature feature = featureBuilder.buildFeature(null);
                features.add(feature);
            }
            StringWriter writer = new StringWriter();
            fjson.writeFeatureCollection(collection, writer);

            jsonStr = writer.toString();
            //System.out.println(String.format("--->wkt2JsonEx: %s ", jsonStr));
        }

        return jsonStr;
    }

    /**
     * GeoJson转换为Wkt图形数据。根据GeoJson的Geometry类型输出。
     * 如果Geometry图形是MultiPolygon，则输出MultiPolygon格式的Wkt（不转换为polygon）
     *
     * @param gjson
     * @return
     */
    public static List<String> geoJson2Wkt(GeoJson gjson) {
        List<String> wkts = new ArrayList<String>();

        List<GeoJsonFeature> features = gjson.getFeatures();
        for(GeoJsonFeature fea: features) {
            GeoJsonGeometry geo = fea.getGeometry();
            String geomStr = JSON.toJSONString(geo.getCoordinates());
            System.out.println("--->"+JSON.toJSONString(geo.getCoordinates()));

            String wkt="";
            String geoType = geo.getType();
            switch(geoType.toLowerCase()) {
                case "polygon":
                {
                    //double[][][]  polygonCoords
                    JSONArray polygonLines = JSON.parseArray(geomStr);
                    StringBuilder sb = new StringBuilder();
                    sb.append("POLYGON(");
                    for(int i=0; i<polygonLines.size(); i++) {
                        //double[][] line
                        JSONArray line = polygonLines.getJSONArray(i);
                        sb.append("(");
                        for(int j=0; j<line.size(); j++) {
                            // double[] pt
                            JSONArray pt = line.getJSONArray(j);
                            double x = pt.getDoubleValue(0);
                            double y = pt.getDoubleValue(1);
                            //System.out.println(String.format("--->%f, %f", x,y));
                            sb.append(String.format("%f %f", x,y));
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append(")");

                    wkt=sb.toString();
                    wkts.add(wkt);
                    break;
                }
                case "multipolygon":
                {
                    JSONArray multiPolygons= JSON.parseArray(geomStr);
                    StringBuilder sb = new StringBuilder();
                    sb.append("MULTIPOLYGON(");
                    for(int k=0; k<multiPolygons.size(); k++) {
                        //double[][][]  polygonCoords
                        JSONArray polygonLines = multiPolygons.getJSONArray(k);
                        sb.append("(");
                        for(int i=0; i<polygonLines.size(); i++) {
                            //double[][] line
                            JSONArray linePoints = polygonLines.getJSONArray(i);
                            sb.append("(");
                            for(int j=0; j<linePoints.size(); j++) {
                                // double[] pt
                                JSONArray pt = linePoints.getJSONArray(j);
                                double x = pt.getDoubleValue(0);
                                double y = pt.getDoubleValue(1);
                                //System.out.println(String.format("--->%f, %f", x,y));
                                sb.append(String.format("%f %f", x,y));
                                sb.append(",");
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append(")");
                        }
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append(")");

                    wkt = sb.toString();
                    wkts.add(wkt);

                    break;
                }
            }
        }

        return wkts;
    }

    /**
     * GeoJson转换为Wkt图形数据。全部统一输出为Polygon格式的Wkt
     *
     * @param gJson
     * @return
     */
    public static List<String> geoJson2WktEx(GeoJson gJson) {
        List<String> wkts = new ArrayList<String>();

        List<GeoJsonFeature> features = gJson.getFeatures();
        for(GeoJsonFeature fea: features) {
            GeoJsonGeometry geom = fea.getGeometry();
            String geomStr =JSON.toJSONString(geom.getCoordinates());
            //System.out.println("--->"+JSON.toJSONString(geo.getCoordinates()));

            String wkt="";
            String geoType = geom.getType();
            switch(geoType.toLowerCase()) {
                case "polygon":
                {
                    //double[][][]  polygonCoords
                    JSONArray polygonLines = JSON.parseArray(geomStr);
                    StringBuilder sb = new StringBuilder();
                    sb.append("POLYGON(");
                    for(int i=0; i<polygonLines.size(); i++) {
                        //double[][] line
                        JSONArray line = polygonLines.getJSONArray(i);
                        sb.append("(");
                        for(int j=0; j<line.size(); j++) {
                            // double[] pt
                            JSONArray pt = line.getJSONArray(j);
                            double x = pt.getDoubleValue(0);
                            double y = pt.getDoubleValue(1);
                            //System.out.println(String.format("--->%f, %f", x,y));
                            sb.append(String.format("%f %f", x,y));
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");
                    }
                    sb.append(")");

                    wkt=sb.toString();
                    wkts.add(wkt);
                    break;
                }
                case "multipolygon":
                {
                    JSONArray multiPolygons= JSON.parseArray(geomStr);
                    for(int k=0; k<multiPolygons.size(); k++) {
                        StringBuilder sb = new StringBuilder();
                        //double[][][]  polygonCoords
                        JSONArray polygonLines = multiPolygons.getJSONArray(k);
                        sb.append("POLYGON(");
                        for(int i=0; i<polygonLines.size(); i++) {
                            //double[][] line
                            JSONArray linePoints = polygonLines.getJSONArray(i);
                            sb.append("(");
                            for(int j=0; j<linePoints.size(); j++) {
                                // double[] pt
                                JSONArray pt = linePoints.getJSONArray(j);
                                double x = pt.getDoubleValue(0);
                                double y = pt.getDoubleValue(1);
                                //System.out.println(String.format("--->%f, %f", x,y));
                                sb.append(String.format("%f %f", x,y));
                                sb.append(",");
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        wkt = sb.toString();
                        wkts.add(wkt);
                    }

                    break;
                }
            }
        }

        return wkts;
    }

    /**
     * GeoJsonGeometry转换为Wkt图形数据。全部统一输出为Polygon格式的Wkt
     * @param geom GeoJsonGeometry
     * @return
     */
    public static List<String> geoJsonGeometry2WktEx(GeoJsonGeometry geom) {
        List<String> wkts = new ArrayList<String>();

        String geomStr =JSON.toJSONString(geom.getCoordinates());
        //System.out.println("--->"+JSON.toJSONString(geo.getCoordinates()));

        String wkt="";
        String geoType = geom.getType();
        switch(geoType.toLowerCase()) {
            case "polygon":
            {
                //double[][][]  polygonCoords
                JSONArray polygonLines = JSON.parseArray(geomStr);
                StringBuilder sb = new StringBuilder();
                sb.append("POLYGON(");
                for(int i=0; i<polygonLines.size(); i++) {
                    //double[][] line
                    JSONArray line = polygonLines.getJSONArray(i);
                    sb.append("(");
                    for(int j=0; j<line.size(); j++) {
                        // double[] pt
                        JSONArray pt = line.getJSONArray(j);
                        double x = pt.getDoubleValue(0);
                        double y = pt.getDoubleValue(1);
                        //System.out.println(String.format("--->%f, %f", x,y));
                        sb.append(String.format("%f %f", x,y));
                        sb.append(",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append("),");
                }
                sb.deleteCharAt(sb.length() - 1);
                sb.append(")");

                wkt=sb.toString();
                wkts.add(wkt);
                break;
            }
            case "multipolygon":
            {
                JSONArray multiPolygons= JSON.parseArray(geomStr);
                for(int k=0; k<multiPolygons.size(); k++) {
                    StringBuilder sb = new StringBuilder();
                    //double[][][]  polygonCoords
                    JSONArray polygonLines = multiPolygons.getJSONArray(k);
                    sb.append("POLYGON(");
                    for(int i=0; i<polygonLines.size(); i++) {
                        //double[][] line
                        JSONArray linePoints = polygonLines.getJSONArray(i);
                        sb.append("(");
                        for(int j=0; j<linePoints.size(); j++) {
                            // double[] pt
                            JSONArray pt = linePoints.getJSONArray(j);
                            double x = pt.getDoubleValue(0);
                            double y = pt.getDoubleValue(1);
                            //System.out.println(String.format("--->%f, %f", x,y));
                            sb.append(String.format("%f %f", x,y));
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append(")");

                    wkt = sb.toString();
                    wkts.add(wkt);
                }

                break;
            }
        }

        return wkts;
    }


    /**
     * GeoJson转换为Polygon。
     *
     * @param gJson
     * @return
     */
    public static List<Polygon> geoJson2Polygon(GeoJson gJson){
        List<Polygon> polygons = new ArrayList<Polygon>();

        WKTReader reader = new WKTReader(geometryFactory);
        List<GeoJsonFeature> features = gJson.getFeatures();
        for(int f=0; f<features.size(); f++) {
            GeoJsonFeature geoFeas = features.get(f);
            GeoJsonGeometry geom = geoFeas.getGeometry();

            String geomStr =JSON.toJSONString(geom.getCoordinates());
            String geoType= geom.getType();
            switch(geoType.toLowerCase()) {
                case "polygon":
                {
                    JSONArray polygonLines = JSON.parseArray(geomStr);
                    StringBuilder sb = new StringBuilder();
                    sb.append("POLYGON(");
                    for(int i=0; i<polygonLines.size(); i++) {
                        JSONArray line = polygonLines.getJSONArray(i);
                        sb.append("(");
                        for(int j=0; j<line.size(); j++) {
                            JSONArray pt = line.getJSONArray(j);
                            double x = pt.getDoubleValue(0);
                            double y = pt.getDoubleValue(1);

                            sb.append(String.format("%f %f", x,y));
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append(")");

                    try {
                        String wkt = sb.toString();
                        Polygon polygon = (Polygon) reader.read(wkt);

                        polygons.add(polygon);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                    break;
                }

                case "multipolygon":
                {
                    JSONArray multiPolygons= JSON.parseArray(geomStr);
                    for(int k=0; k<multiPolygons.size(); k++) {
                        StringBuilder sb = new StringBuilder();
                        JSONArray polygonLines = multiPolygons.getJSONArray(k);

                        sb.append("POLYGON(");
                        for(int i=0; i<polygonLines.size(); i++) {
                            JSONArray linePoints = polygonLines.getJSONArray(i);
                            sb.append("(");
                            for(int j=0; j<linePoints.size(); j++) {
                                JSONArray pt = linePoints.getJSONArray(j);
                                double x = pt.getDoubleValue(0);
                                double y = pt.getDoubleValue(1);

                                sb.append(String.format("%f %f", x,y));
                                sb.append(",");
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        try {
                            String wkt = sb.toString();
                            Polygon polygon = (Polygon) reader.read(wkt);

                            polygons.add(polygon);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                }
            }
        }

        return polygons;
    }

    public static List<Polygon> geoJsonGeometry2Polygon(GeoJsonGeometry geom){
        List<Polygon> polygons = new ArrayList<Polygon>();

        WKTReader reader = new WKTReader(geometryFactory);
        String geomStr = JSON.toJSONString(geom.getCoordinates());
        String geoType = geom.getType();
        switch(geoType.toLowerCase()) {
            case "polygon":
            {
                JSONArray polygonLines = JSON.parseArray(geomStr);
                StringBuilder sb = new StringBuilder();
                sb.append("POLYGON(");
                for(int i=0; i<polygonLines.size(); i++) {
                    JSONArray line = polygonLines.getJSONArray(i);
                    sb.append("(");
                    for(int j=0; j<line.size(); j++) {
                        JSONArray pt = line.getJSONArray(j);
                        double x = pt.getDoubleValue(0);
                        double y = pt.getDoubleValue(1);

                        sb.append(String.format("%f %f", x,y));
                        sb.append(",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append("),");
                }
                sb.deleteCharAt(sb.length() - 1);
                sb.append(")");
                String recordWkt="";
                try {
                    String wkt = sb.toString();
                    recordWkt=wkt;
                    Polygon polygon = (Polygon) reader.read(wkt);

                    polygons.add(polygon);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

                break;
            }

            case "multipolygon":
            {
                JSONArray multiPolygons= JSON.parseArray(geomStr);
                for(int k=0; k<multiPolygons.size(); k++) {
                    StringBuilder sb = new StringBuilder();
                    JSONArray polygonLines = multiPolygons.getJSONArray(k);

                    sb.append("POLYGON(");
                    for(int i=0; i<polygonLines.size(); i++) {
                        JSONArray linePoints = polygonLines.getJSONArray(i);
                        sb.append("(");
                        for(int j=0; j<linePoints.size(); j++) {
                            JSONArray pt = linePoints.getJSONArray(j);
                            double x = pt.getDoubleValue(0);
                            double y = pt.getDoubleValue(1);

                            sb.append(String.format("%f %f", x,y));
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append(")");

                    try {
                        String wkt = sb.toString();
                        Polygon polygon = (Polygon) reader.read(wkt);

                        polygons.add(polygon);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                break;
            }
        }


        return polygons;
    }

    /**
     * GeoJson转换为Geometry
     * @param gJson
     * @return
     */
    public static List<Geometry> geoJson2Geometry(GeoJson gJson){
        List<Geometry> polygons = new ArrayList<Geometry>();

        WKTReader reader = new WKTReader(geometryFactory);
        List<GeoJsonFeature> features = gJson.getFeatures();
        for(int f=0; f<features.size(); f++) {
            GeoJsonFeature geoFeas= features.get(f);
            GeoJsonGeometry geom= geoFeas.getGeometry();

            String geomStr =JSON.toJSONString(geom.getCoordinates());
            String geoType= geom.getType();
            switch(geoType.toLowerCase()) {
                case "polygon":
                {
                    JSONArray polygonLines = JSON.parseArray(geomStr);
                    StringBuilder sb = new StringBuilder();
                    sb.append("POLYGON(");
                    for(int i=0; i<polygonLines.size(); i++) {
                        JSONArray line = polygonLines.getJSONArray(i);
                        sb.append("(");
                        for(int j=0; j<line.size(); j++) {
                            JSONArray pt = line.getJSONArray(j);
                            double x = pt.getDoubleValue(0);
                            double y = pt.getDoubleValue(1);

                            sb.append(String.format("%f %f", x,y));
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append(")");

                    try {
                        String wkt = sb.toString();
                        Geometry polygon = reader.read(wkt);

                        polygons.add(polygon);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                    break;
                }

                case "multipolygon":
                {
                    JSONArray multiPolygons= JSON.parseArray(geomStr);
                    for(int k=0; k<multiPolygons.size(); k++) {
                        StringBuilder sb = new StringBuilder();
                        JSONArray polygonLines = multiPolygons.getJSONArray(k);

                        sb.append("POLYGON(");
                        for(int i=0; i<polygonLines.size(); i++) {
                            JSONArray linePoints = polygonLines.getJSONArray(i);
                            sb.append("(");
                            for(int j=0; j<linePoints.size(); j++) {
                                JSONArray pt = linePoints.getJSONArray(j);
                                double x = pt.getDoubleValue(0);
                                double y = pt.getDoubleValue(1);

                                sb.append(String.format("%f %f", x,y));
                                sb.append(",");
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        try {
                            String wkt = sb.toString();
                            Geometry polygon = reader.read(wkt);

                            polygons.add(polygon);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                }
            }
        }

        return polygons;
    }


    /**
     * GeoJson转换为STGeoFeature
     *
     * @param gJson
     * @return
     */
    public static List<StgeoFeature> geoJson2STGeoFeature(GeoJson gJson) {

        List<StgeoFeature> stgeoFeatures = new ArrayList<StgeoFeature>();

        WKTReader reader = new WKTReader(geometryFactory);
        List<GeoJsonFeature> features = gJson.getFeatures();
        for(int f=0; f<features.size(); f++) {
            GeoJsonFeature geoFeas = features.get(f);
            //System.out.println();

            GeoJsonGeometry geom = geoFeas.getGeometry(); //几何图形
            Map<String,Object> properties = geoFeas.getProperties(); //属性集合
            for(Map.Entry<String, Object> prop: properties.entrySet()) {
                String key = prop.getKey();
                Object val = prop.getValue();
                String attrVal = "";
                try {
                    //attrVal = new String(val.toString().getBytes("UTF-8"), "GBK");
                    attrVal = (val == null ? "" : val.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //System.out.println(String.format("-->%s, %s", key, attrVal ));
            }

            String geomStr =JSON.toJSONString(geom.getCoordinates());
            if( StringUtil.isNullOrEmpty(geomStr) ) {
                continue;
            }

            String geoType = geom.getType();
            switch(geoType.toLowerCase()) {
                case "polygon":
                {
                    JSONArray polygonLines = JSON.parseArray(geomStr);
                    StringBuilder sb = new StringBuilder();
                    sb.append("POLYGON (");
                    for(int i=0; i<polygonLines.size(); i++) {
                        JSONArray line = polygonLines.getJSONArray(i);
                        sb.append("(");
                        for(int j=0; j<line.size(); j++) {
                            JSONArray pt = line.getJSONArray(j);
                            double x = pt.getDoubleValue(0);
                            double y = pt.getDoubleValue(1);

                            sb.append(String.format("%f %f", x,y));
                            sb.append(",");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append("),");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    sb.append(")");


                    try {
                        String wkt = sb.toString();
                        //System.out.println("--->wkt: "+wkt);

                        Geometry polygon = reader.read(wkt);

                        StgeoFeature stgeoFea = new StgeoFeature();
                        stgeoFea.setGeometry(polygon);
                        stgeoFea.setProperties(properties);

                        stgeoFeatures.add(stgeoFea);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                    break;
                }

                case "multipolygon":
                {
                    JSONArray multiPolygons = JSON.parseArray(geomStr);
                    for(int k=0; k<multiPolygons.size(); k++) {
                        StringBuilder sb = new StringBuilder();
                        JSONArray polygonLines = multiPolygons.getJSONArray(k);

                        sb.append("POLYGON (");
                        for(int i=0; i<polygonLines.size(); i++) {
                            JSONArray linePoints = polygonLines.getJSONArray(i);
                            sb.append("(");
                            for(int j=0; j<linePoints.size(); j++) {
                                JSONArray pt = linePoints.getJSONArray(j);
                                double x = pt.getDoubleValue(0);
                                double y = pt.getDoubleValue(1);

                                sb.append(String.format("%f %f", x,y));
                                sb.append(",");
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        try {
                            String wkt = sb.toString();
                            //System.out.println("--->wkt: "+wkt);

                            Geometry polygon = reader.read(wkt);

                            StgeoFeature stgeoFea = new StgeoFeature();
                            stgeoFea.setGeometry(polygon);
                            stgeoFea.setProperties(properties);

                            stgeoFeatures.add(stgeoFea);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                }
            }
        }

        return stgeoFeatures;
    }

    public static Polygon createPolygon(Map<Integer,List<Coordinate>> polygonCoordsList) {
        int lineSize =  polygonCoordsList.size();

        Polygon polygon =null;
        if( lineSize==1 ) {
            //创建面
            GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
            Coordinate[] coords  = (Coordinate[]) polygonCoordsList.get(0).toArray();
            LinearRing ring = geometryFactory.createLinearRing(coords);

            LinearRing holes[] = null; // use LinearRing[] to represent holes
            polygon = geometryFactory.createPolygon(ring, holes);
        }else {
            //创建面和洞
            GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
            Coordinate[] coords1  = (Coordinate[]) polygonCoordsList.get(0).toArray();
            LinearRing ring1 = geometryFactory.createLinearRing(coords1);
            //洞
            List<LinearRing> holeList = new ArrayList<LinearRing>(); // use LinearRing[] to represent holes
            for(int i=1; i<polygonCoordsList.size(); i++) {
                Coordinate[] coords  = (Coordinate[]) polygonCoordsList.get(i).toArray();
                LinearRing ring = geometryFactory.createLinearRing(coords);

                holeList.add(ring);
            }
            LinearRing[]  holes= (LinearRing[]) holeList.toArray();
            polygon = geometryFactory.createPolygon(ring1, holes);
        }
        return polygon;
    }

    /**
     * MultiPolygon与Polygon相互转换
     *
     * @param wktPolygon
     * @return
     * @throws ParseException
     */
    public static MultiPolygon polygon2MultiPolygon(String wktPolygon) throws ParseException {
        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
        WKTReader reader = new WKTReader( geometryFactory );

        //Polygon p = (Polygon) reader.read("POLYGON ((115.05948119466 22.8626134301296, 115.06225289824 22.8626134301296, 115.06225289824 22.8523347587268, 115.05925618009766 22.85237940437907, 115.05948119466 22.8626134301296))");
        Polygon p = (Polygon) reader.read(wktPolygon);
        GeometryFactory gf = new GeometryFactory();
        MultiPolygon mPoly = null;
        if (p instanceof Polygon){
            Polygon[] polys = new Polygon[1];
            polys[0] = p;
            mPoly = gf.createMultiPolygon(polys);
        }
        return mPoly;
    }

    public static List<Polygon> multipolygon2Polygons(MultiPolygon multiPoly){
        List<Polygon> polygons = new ArrayList<Polygon>();

        for(int i=0; i<multiPoly.getNumGeometries(); i++) {
            Polygon singleGeo =(Polygon) multiPoly.getGeometryN(i); //获取其中每一个geometry
            polygons.add(singleGeo);
        }
        return polygons;

    }


    /**
     * 获取shapefile的业务字段结构（字段名）
     *
     * @param shppath
     * @return
     */
    public static Map<String,String> getYwPropertieSchemas(String shppath){
        ShapefileDataStore shapefileDataStore=null;
        File file= new File(shppath);
        String encoding="GBK";

        // 1-2转换图形
        Map<String,String> properties = new HashMap<String,String>();
        try{
            URL url=file.toURI().toURL();
            shapefileDataStore= new ShapefileDataStore(url);
            shapefileDataStore.setCharset(Charset.forName(encoding));
            String typeName = shapefileDataStore.getTypeNames()[0];

            SimpleFeatureSource featureSource = shapefileDataStore.getFeatureSource(typeName);
            FeatureType schema = featureSource.getSchema();

            int fieldCount = ((SimpleFeatureType) schema).getAttributeCount();
            for(int i=0; i<fieldCount; i++){
                AttributeType attrType = ((SimpleFeatureType) schema).getType(i);
                //字段名
                String attrName = attrType.getName().toString();
                //字段类型
                String attrTypeBinding =  attrType.getBinding().toString();

                int indxeOfLastDot=attrTypeBinding.lastIndexOf(".");
                String attrTypeName = attrTypeBinding.substring(indxeOfLastDot+1,attrTypeBinding.length());
                System.out.println(String.format("--->attrName: %s, type: %s ",attrName,attrTypeName));
                if("polygon".equalsIgnoreCase(attrName.toLowerCase()) || "multipolygon".equalsIgnoreCase(attrName.toLowerCase())){
                    continue;
                }
                properties.put(attrName, attrTypeName);
            }
            shapefileDataStore.dispose();
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

        return properties;

    }

    /**
     * 根据字段值，筛选shpfile的部分图斑
     *
     * @param shppath
     * @param targetFieldName
     * @param targetFieldVal
     * @return
     */
    public static Map<String, StgeoFeature> getHydltbShpByFilter(String shppath, String targetFieldName, String targetFieldVal){
        ShapefileDataStore shapefileDataStore=null;
        File file= new File(shppath);
        String encoding="GBK";

        // 1-2转换图形
        Map<String, StgeoFeature> stgeoFeatureMap = new HashMap<String, StgeoFeature>();
        try{
            URL url=file.toURI().toURL();
            shapefileDataStore= new ShapefileDataStore(url);
            shapefileDataStore.setCharset(Charset.forName(encoding));
            String typeName = shapefileDataStore.getTypeNames()[0];

            SimpleFeatureSource featureSource = shapefileDataStore.getFeatureSource(typeName);
            //按字段进行筛选
            FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
            Filter filter = filterFactory.equals(filterFactory.property(targetFieldName), filterFactory.literal(targetFieldVal));

            SimpleFeatureCollection simpleFeatureCollection = featureSource.getFeatures(filter);
            SimpleFeatureIterator featureIterator = simpleFeatureCollection.features();
            while(featureIterator.hasNext()){
                SimpleFeature sf = featureIterator.next();

                //1-图形
                Geometry geom = (Geometry) sf.getDefaultGeometry();
                List<Object> attrs = sf.getAttributes();
                for(Object attr: attrs){
                    String ss = attr.toString();
                    System.out.println(ss);
                }
                String tbbh = sf.getProperties("TBBH") != null ? sf.getProperties("TBBH").toString():"";

                //2-属性
                Map<String,Object> propMaps= new HashMap<String,Object>();
                Collection<Property> props = sf.getProperties();
                Iterator<Property> propIter = props.iterator();
                while (propIter.hasNext()){
                    Property prop = propIter.next();
                    Name propName =prop.getName();
                    PropertyType propType= prop.getType();

                    String propTypeName= propType.getName().toString();
                    Object propVal= prop.getValue();

                    propMaps.put(propName.toString(),propVal);
                    System.out.println(String.format("--->propName: %s, propType: %s, propValue：%s",propName.toString(),propTypeName, propVal));
                }

                StgeoFeature stgeo = new StgeoFeature();
                stgeo.setGeometry(geom);
                stgeo.setProperties(propMaps);

                stgeoFeatureMap.put(tbbh,stgeo);
            }
            featureIterator.close();
            shapefileDataStore.dispose();
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

        return stgeoFeatureMap;
    }

    /**
     * List<StgeoFeature> 转GeoJson
     *
     * @param stgeoFeas
     * @return
     */
    public static String stgeoFeas2GeoJson(List<StgeoFeature> stgeoFeas) throws SchemaException, ParseException, IOException {
        String jsonStr = null;

        SimpleFeatureType TYPE = DataUtilities.createType("Link", "geometry:Polygon");
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);

        //GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
        WKTReader reader = new WKTReader(geometryFactory);
        FeatureJSON fjson = new FeatureJSON();

        List<SimpleFeature> features = new ArrayList<>();
        SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);
        for (StgeoFeature stgeoFea: stgeoFeas ) {
            Geometry geom = stgeoFea.getGeometry();
            String wkt = geom.toText();

            //转换wkt为polygon
            Polygon polygon = (Polygon) reader.read(wkt);
            featureBuilder.add(polygon);
            SimpleFeature feature = featureBuilder.buildFeature(null);
            features.add(feature);
        }
        StringWriter writer = new StringWriter();
        fjson.writeFeatureCollection(collection, writer);

        jsonStr = writer.toString();
        return jsonStr;
    }

    public static String stgeoFea2s2GeoJson(List<StgeoFeature2> stgeoFeas, String geoType, int decimalsOfCoord) throws SchemaException, ParseException, IOException {
        String jsonStr = null;

        SimpleFeatureType TYPE = DataUtilities.createType("Link", "geometry:Polygon");
        switch(geoType.toLowerCase()) {
            case "point":
            {
                TYPE = DataUtilities.createType("Link", "geometry:Point");
                break;
            }
            case "multipoint":
            {
                TYPE = DataUtilities.createType("Link", "geometry:MultiPoint");
                break;
            }
            case "linestring":
            {
                TYPE = DataUtilities.createType("Link", "geometry:LineString");
                break;
            }
            case "multilinestring":
            {
                TYPE = DataUtilities.createType("Link", "geometry:MultiLineString");
                break;
            }
            case "polygon":
            {
                TYPE = DataUtilities.createType("Link", "geometry:Polygon");
                break;
            }
            case "multipolygon":
            {
                TYPE = DataUtilities.createType("Link", "geometry:MultiPolygon");
                break;
            }
        }

        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);

        //GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
        WKTReader reader = new WKTReader(geometryFactory);
        GeometryJSON g = new GeometryJSON(decimalsOfCoord);// 这个参数必须测试，不然精度丢失
        FeatureJSON fjson = new FeatureJSON(g);

        List<SimpleFeature> features = new ArrayList<>();
        SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);
        for (StgeoFeature2 stgeoFea: stgeoFeas ) {
            String wkt = stgeoFea.getGeomWkt();
            Map<String,Object> props= stgeoFea.getProperties();

            //转换wkt为polygon
            //Polygon polygon = (Polygon) reader.read(wkt);
            //featureBuilder.add(polygon);
            switch(geoType.toLowerCase()) {
                case "point":
                {
                    Point point = (Point) reader.read(wkt);
                    featureBuilder.add(point);
                    break;
                }
                case "multipoint":
                {
                    MultiPoint mulpoint = (MultiPoint) reader.read(wkt);
                    featureBuilder.add(mulpoint);
                    break;
                }
                case "linestring":
                {
                    LineString line = (LineString) reader.read(wkt);
                    featureBuilder.add(line);
                    break;
                }
                case "multilinestring":
                {
                    MultiLineString multiline = (MultiLineString) reader.read(wkt);
                    featureBuilder.add(multiline);
                    break;
                }
                case "polygon":
                {
                    //转换wkt为polygon
                    Polygon polygon = (Polygon) reader.read(wkt);
                    featureBuilder.add(polygon);
                    break;
                }
                case "multipolygon":
                {
                    MultiPolygon multipolygon = (MultiPolygon) reader.read(wkt);
                    featureBuilder.add(multipolygon);
                    break;
                }
            }

            SimpleFeature feature = featureBuilder.buildFeature(null);
            //属性,这里有问题。字段结构未定义
            /*
            for(Map.Entry<String, Object> ent: props.entrySet()) {
            	String propKey= ent.getKey();
            	Object propValue = ent.getValue();
            	if(!StringUtil.isNullOrEmpty(propKey) && !StringUtil.isNullOrEmpty(propValue)) {
            		feature.setAttribute(propKey, propValue);
            	}
            }
            */

            features.add(feature);
        }
        StringWriter writer = new StringWriter();
        fjson.writeFeatureCollection(collection, writer);

        jsonStr = writer.toString();
        return jsonStr;
    }

    /**
     * 保存图形为新的SHP文件
     *
     * @param polygons  待保存的图形
     * @param filePath  SHP路径
     *
     * @throws SchemaException
     * @throws IOException
     */
    public static void savePolygonsAsNewSHP(List<Polygon> polygons,String filePath) throws SchemaException, IOException {

        /**************第一步 Polygon转geojson *****************/
        System.out.println();
        System.out.println("**************第一步 Polygon转geojson *****************");
        //新建
        final SimpleFeatureType TYPE = DataUtilities.createType("Link", "geometry:Polygon," + // <- the geometry
                "ffid:String," + // <- a String attribute
                "bz:String" );
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
        List<SimpleFeature> features = new ArrayList<>();
        for(Polygon polygon: polygons) {
            //Feature
            String uuid = UUID.randomUUID().toString();
            featureBuilder.add(polygon);
            featureBuilder.add(uuid);
            featureBuilder.add("new shp");
            SimpleFeature feature = featureBuilder.buildFeature(null);

            features.add(feature);
        }

        //写入
        StringWriter writer = new StringWriter();
        SimpleFeatureCollection feaCollection = new ListFeatureCollection(TYPE, features);
        FeatureJSON fjson = new FeatureJSON();
        fjson.writeFeatureCollection(feaCollection, writer);

        //导出geojson文件
        String geojson = writer.toString();
        System.out.println();
        System.out.println("--->featurecollection geojson: %s " + geojson);


        /**************第二步 geojson保存为SHP *****************/
        System.out.println();
        System.out.println("**************第二步 geojson保存为SHP *****************");
        File shpFile = new File(filePath);

        // 根据geojson生成shapefile
        String crs_wkt = "GEOGCS[\"China Geodetic Coordinate System 2000\","
                + "    DATUM[\"China_2000\","
                + "        SPHEROID[\"CGCS2000\",6378137,298.257222101,"
                + "            AUTHORITY[\"EPSG\",\"1024\"]],"
                + "        AUTHORITY[\"EPSG\",\"1043\"]],"
                + "    PRIMEM[\"Greenwich\",0,"
                + "        AUTHORITY[\"EPSG\",\"8901\"]],"
                + "    UNIT[\"degree\",0.0174532925199433,"
                + "        AUTHORITY[\"EPSG\",\"9122\"]],"
                + "    AUTHORITY[\"EPSG\",\"4490\"]]";
        String geometryType = "esriGeometryPolygon";
        String fields = "[{\"name\":\"ffid\",\"type\":\"esriFieldTypeString\",\"alias\":\"ffid\"},{\"name\":\"bz\",\"type\":\"esriFieldTypeString\",\"alias\":\"bz\"}]";
        try {
            GeoJson2Shapefile.createShapefile1(shpFile, geojson, crs_wkt, geometryType.toLowerCase(), fields);
        } catch (IOException | FactoryException e) {
            e.printStackTrace();
        }
    }

    /**
     * 保存图形为新的SHP文件
     *
     * @param polygons  待保存的图形
     * @param filePath  SHP路径
     * @param crs_wkt   投影wkt
     *
     * @throws SchemaException
     * @throws IOException
     */
    public static void savePolygonsAsNewSHP(List<Polygon> polygons, String filePath, String crs_wkt)
            throws SchemaException, IOException {

        /************** 第一步 Polygon转geojson *****************/
        System.out.println();
        System.out.println("**************第一步 Polygon转geojson *****************");
        // 新建
        final SimpleFeatureType TYPE = DataUtilities.createType("Link", "geometry:Polygon," + // <- the geometry
                "ffid:String," + // <- a String attribute
                "bz:String");
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
        List<SimpleFeature> features = new ArrayList<>();
        for (Polygon polygon : polygons) {
            // Feature
            String uuid = UUID.randomUUID().toString();
            featureBuilder.add(polygon);
            featureBuilder.add(uuid);
            featureBuilder.add("sss test");

            SimpleFeature feature = featureBuilder.buildFeature(null);
            features.add(feature);
        }

        // 写入
        StringWriter writer = new StringWriter();
        SimpleFeatureCollection feaCollection = new ListFeatureCollection(TYPE, features);
        FeatureJSON fjson = new FeatureJSON();
        fjson.writeFeatureCollection(feaCollection, writer);

        // 导出geojson文件
        String geojson = writer.toString();
        System.out.println();
        System.out.println("--->featurecollection geojson: %s " + geojson);

        /************** 第二步 geojson保存为SHP *****************/
        System.out.println();
        System.out.println("**************第二步 geojson保存为SHP *****************");
        File shpFile = new File(filePath);

        // 根据geojson生成shapefile
        String geometryType = "esriGeometryPolygon";
        String fields = "[{\"name\":\"ffid\",\"type\":\"esriFieldTypeString\",\"alias\":\"ffid\"},{\"name\":\"bz\",\"type\":\"esriFieldTypeString\",\"alias\":\"bz\"}]";
        try {
            GeoJson2Shapefile.createShapefile1(shpFile, geojson, crs_wkt, geometryType.toLowerCase(), fields);
        } catch (IOException | FactoryException e) {
            e.printStackTrace();
        }

    }

    /**
     * 保存图形为新的SHP文件
     *
     * @param feaCollection  待保存的图形
     * @param filePath  SHP路径
     * @param crs_wkt   投影wkt
     *
     * @throws SchemaException
     * @throws IOException
     */
    public static void saveFeatureCollectionAsNewSHP(SimpleFeatureCollection feaCollection, String filePath, String crs_wkt)
            throws SchemaException, IOException {

        /************** 第一步 Polygon转geojson *****************/
        System.out.println();
        System.out.println("**************第一步 Polygon转geojson *****************");
        String ywFieldsStr = "DKBH:String," + "DLBM:String," + "DLMC:String,"+ "DJMJ:Double,"+ "BZ:String";

        // 新建
        final SimpleFeatureType TYPE = DataUtilities.createType("Link", "geometry:Polygon," + ywFieldsStr);
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);

        // 写入
        StringWriter writer = new StringWriter();
        FeatureJSON fjson = new FeatureJSON();
        fjson.writeFeatureCollection(feaCollection, writer);

        // 导出geojson文件
        String geojson = writer.toString();
        System.out.println();
        System.out.println("--->featurecollection geojson: %s " + geojson);

        /************** 第二步 geojson保存为SHP *****************/
        System.out.println();
        System.out.println("**************第二步 geojson保存为SHP *****************");
        File shpFile = new File(filePath);

        // 根据geojson生成shapefile
        String geometryType = "esriGeometryPolygon";
        String fields = "[" +
                "{\"name\":\"DKBH\",\"type\":\"esriFieldTypeString\",\"alias\":\"DKBH\"}," +
                "{\"name\":\"DLBM\",\"type\":\"esriFieldTypeString\",\"alias\":\"DLBM\"}," +
                "{\"name\":\"DLMC\",\"type\":\"esriFieldTypeString\",\"alias\":\"DLMC\"}," +
                "{\"name\":\"DJMJ\",\"type\":\"esriFieldTypeDouble\",\"alias\":\"DJMJ\"}," +
                "{\"name\":\"BZ\",\"type\":\"esriFieldTypeString\",\"alias\":\"BZ\"}" +
                "]";

        try {
            GeoJson2Shapefile.createShapefile1(shpFile, geojson, crs_wkt, geometryType.toLowerCase(), fields);
        } catch (IOException | FactoryException e) {
            e.printStackTrace();
        }

    }

    /**
     * 转换shp为stgeofea2 list
     *
     * @param shpPath
     * @param decimalsOfCoord
     * @return
     */
    public static List<StgeoFeature2> convertShp2StgeoFea(String shpPath, int decimalsOfCoord) {
        List<StgeoFeature2> stgeoFeature2List = new ArrayList<StgeoFeature2>();

        ShapefileDataStore shpDataStore = null;
        GeometryJSON g = new GeometryJSON(decimalsOfCoord);// 这个参数必须测试，不然精度丢失
        FeatureJSON fjson = new FeatureJSON(g);
        File file = new File(shpPath);

        try {
            URL url = file.toURI().toURL();
            shpDataStore = new ShapefileDataStore(url);
            shpDataStore.setCharset(Charset.forName("GBK"));
            String typeName = shpDataStore.getTypeNames()[0];

            // 遍历所有要素
            // land
            SimpleFeatureSource featureSource = shpDataStore.getFeatureSource(typeName);
            SimpleFeatureCollection feaCollections = featureSource.getFeatures();

            SimpleFeatureIterator feaIter = feaCollections.features();
            while (feaIter.hasNext()) {
                // block
                SimpleFeature feature = feaIter.next();
                // 获取Feature相关信息
                StringWriter strWriter = new StringWriter();
                fjson.writeFeature(feature, strWriter);
                String feaJsonString = strWriter.toString();
                // System.out.println(feaJsonString);

                JSONObject feaObject = JSON.parseObject(feaJsonString);
                String feaId = feaObject.getString("id");
                String feaType = feaObject.getString("type");

                StgeoFeature2 stgeoFeature2= new StgeoFeature2();

                System.out.println();
                //System.out.println("--->1. feature properties" );
                JSONObject feaProperties = feaObject.getJSONObject("properties");
                Map<String,Object> props = new HashMap<String,Object>();
                for (Map.Entry<String, Object> entry : feaProperties.entrySet()) {
                    String fieldName = entry.getKey();
                    Object fieldValue = entry.getValue();

                    props.put(fieldName, fieldValue);
                    System.out.println(fieldName + ":" + fieldValue.toString());
                }

                stgeoFeature2.setProperties(props);

                // 获取Geometry相关信息
                //System.out.println("--->2. feature geom" );

                String wkt = "";
                JSONObject geoObject = feaObject.getJSONObject("geometry");
                String geoType = geoObject.getString("type");
                switch(geoType.toLowerCase()) {
                    case "polygon":
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.append("POLYGON(");
                        //double[][][]  polygonCoords
                        JSONArray polygonCoords = geoObject.getJSONArray("coordinates");
                        for (int i = 0; i < polygonCoords.size(); i++) {
                            sb.append("(");
                            JSONArray lineCoords = polygonCoords.getJSONArray(i);
                            for (int j = 0; j < lineCoords.size(); j++) {
                                // ring
                                JSONArray ringCoords = lineCoords.getJSONArray(j);
                                for (int k = 0; k < ringCoords.size(); k++) {
                                    // point
                                    JSONArray ptCoords = ringCoords.getJSONArray(k);
                                    double x = ptCoords.getDoubleValue(0);
                                    double y = ptCoords.getDoubleValue(1);

                                    String coordLine=String.format("%f %f", x, y);
                                    if(!StringUtil.isNullOrEmpty(coordLine)) {
                                        sb.append(coordLine);
                                    }
                                    sb.append(",");
                                }
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        wkt=sb.toString();

                        break;
                    }
                    case "multipolygon":
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.append("MULTIPOLYGON(");

                        JSONArray multiPolygonCoords = geoObject.getJSONArray("coordinates");
                        for (int i = 0; i < multiPolygonCoords.size(); i++) {
                            sb.append("(");
                            for (int j = 0; j < multiPolygonCoords.size(); j++) {
                                sb.append("(");
                                JSONArray polygonCoords = multiPolygonCoords.getJSONArray(j);
                                for (int k = 0; k < polygonCoords.size(); k++) {
                                    // ring
                                    JSONArray ringCoords = polygonCoords.getJSONArray(k);
                                    for (int m = 0; m < ringCoords.size(); m++) {
                                        // point
                                        JSONArray ptCoords = ringCoords.getJSONArray(m);
                                        double x = ptCoords.getDoubleValue(0);
                                        double y = ptCoords.getDoubleValue(1);

                                        String coordLine=String.format("%f %f", x, y);
                                        if(!StringUtil.isNullOrEmpty(coordLine)) {
                                            sb.append(coordLine);
                                        }
                                        sb.append(",");
                                    }
                                }
                                sb.deleteCharAt(sb.length() - 1);
                                sb.append("),");
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        wkt = sb.toString();
                        break;
                    }
                }
                stgeoFeature2.setGeomWkt(wkt);

                stgeoFeature2List.add(stgeoFeature2);
            }

            feaIter.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        shpDataStore.dispose();

        return stgeoFeature2List;
    }

    /**
     * 转换featureCollection为stgeofea2 list
     *
     * @param feaCollections
     * @param decimalsOfCoord
     * @return
     */
    public static List<StgeoFeature2> convertFeaCollection2StgeoFea(SimpleFeatureCollection feaCollections, int decimalsOfCoord) {
        List<StgeoFeature2> stgeoFeatureList = new ArrayList<StgeoFeature2>();

        GeometryJSON g = new GeometryJSON(decimalsOfCoord);// 这个参数必须测试，不然精度丢失
        FeatureJSON fjson = new FeatureJSON(g);

        try {
            SimpleFeatureIterator feaIter = feaCollections.features();
            while (feaIter.hasNext()) {
                // block
                SimpleFeature feature = feaIter.next();
                // 获取Feature相关信息
                StringWriter strWriter = new StringWriter();
                fjson.writeFeature(feature, strWriter);
                String feaJsonString = strWriter.toString();
                // System.out.println(feaJsonString);

                JSONObject feaObject = JSON.parseObject(feaJsonString);
                String feaId = feaObject.getString("id");
                String feaType = feaObject.getString("type");

                StgeoFeature2 stgeoFeature = new StgeoFeature2();

                System.out.println();
                //System.out.println("--->1. feature properties" );
                JSONObject feaProperties = feaObject.getJSONObject("properties");
                Map<String,Object> props = new HashMap<String,Object>();
                for (Map.Entry<String, Object> entry : feaProperties.entrySet()) {
                    String fieldName = entry.getKey();
                    Object fieldValue = entry.getValue();

                    props.put(fieldName, fieldValue);
                    System.out.println(fieldName + ":" + fieldValue.toString());
                }

                stgeoFeature.setProperties(props);

                // 获取Geometry相关信息
                //System.out.println("--->2. feature geom" );

                String wkt = "";
                JSONObject geoObject = feaObject.getJSONObject("geometry");
                String geoType = geoObject.getString("type");
                switch(geoType.toLowerCase()) {
                    case "polygon":
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.append("POLYGON(");
                        //double[][][]  polygonCoords
                        JSONArray polygonCoords = geoObject.getJSONArray("coordinates");
                        for (int i = 0; i < polygonCoords.size(); i++) {
                            sb.append("(");
                            JSONArray lineCoords = polygonCoords.getJSONArray(i);
                            for (int j = 0; j < lineCoords.size(); j++) {
                                // ring
                                JSONArray ringCoords = lineCoords.getJSONArray(j);
                                for (int k = 0; k < ringCoords.size(); k++) {
                                    // point
                                    JSONArray ptCoords = ringCoords.getJSONArray(k);
                                    double x = ptCoords.getDoubleValue(0);
                                    double y = ptCoords.getDoubleValue(1);

                                    String coordLine=String.format("%f %f", x, y);
                                    if(!StringUtil.isNullOrEmpty(coordLine)) {
                                        sb.append(coordLine);
                                    }
                                    sb.append(",");
                                }
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        wkt=sb.toString();
                        break;
                    }
                    case "multipolygon":
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.append("MULTIPOLYGON(");

                        JSONArray multiPolygonCoords = geoObject.getJSONArray("coordinates");
                        for (int i = 0; i < multiPolygonCoords.size(); i++) {
                            sb.append("(");
                            for (int j = 0; j < multiPolygonCoords.size(); j++) {
                                sb.append("(");
                                JSONArray polygonCoords = multiPolygonCoords.getJSONArray(j);
                                for (int k = 0; k < polygonCoords.size(); k++) {
                                    // ring
                                    JSONArray ringCoords = polygonCoords.getJSONArray(k);
                                    for (int m = 0; m < ringCoords.size(); m++) {
                                        // point
                                        JSONArray ptCoords = ringCoords.getJSONArray(m);
                                        double x = ptCoords.getDoubleValue(0);
                                        double y = ptCoords.getDoubleValue(1);

                                        String coordLine=String.format("%f %f", x, y);
                                        if(!StringUtil.isNullOrEmpty(coordLine)) {
                                            sb.append(coordLine);
                                        }
                                        sb.append(",");
                                    }
                                }
                                sb.deleteCharAt(sb.length() - 1);
                                sb.append("),");
                            }
                            sb.deleteCharAt(sb.length() - 1);
                            sb.append("),");
                        }
                        sb.deleteCharAt(sb.length() - 1);
                        sb.append(")");

                        wkt = sb.toString();
                        break;
                    }
                }
                stgeoFeature.setGeomWkt(wkt);
                stgeoFeatureList.add(stgeoFeature);
            }

            feaIter.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return stgeoFeatureList;
    }



    /**
     * wangq  功能测试
     *
     * @param args
     * @throws ParseException
     */
    public static void main(String[] args) throws ParseException {

        Polygon p = JTSGeometryWKTUtil.createCircle(0, 1, 2);
        // 圆上所有的坐标(32个)
        Coordinate coords[] = p.getCoordinates();
        for (Coordinate coord : coords) {
            System.out.println(coord.x + "," + coord.y);
        }

    }
}